package com.xiao.sulingproduct.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiao.sulingproduct.entity.ClassifyEntity;
import com.xiao.sulingproduct.service.ClassifyService;
import com.xiao.sulingpublic.utils.PageUtils;
import com.xiao.sulingpublic.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 商品分类表
 *
 * @author wen
 * @email 1322127758@qq.com
 * @date 2022-03-11 14:46:16
 */
@RestController
@RequestMapping("sulingpxqg/classify")
public class ClassifyController {
    @Autowired
    private ClassifyService classifyService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("sulingpxqg:classify:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = classifyService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 获取指定用户的分类数据
     */
    @RequestMapping("/list/getclassifys")
    public R selectClassify(@RequestParam("username")String username){
        List<ClassifyEntity> classifys = classifyService.list(new QueryWrapper<ClassifyEntity>().eq("cl_member_username", username));
        return R.ok().put("classifys",classifys);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{clId}")
    //@RequiresPermissions("sulingpxqg:classify:info")
    public R info(@PathVariable("clId") Long clId){
		ClassifyEntity classify = classifyService.getById(clId);

        return R.ok().put("classify", classify);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("sulingpxqg:classify:save")
    public R save(@RequestBody ClassifyEntity classify){
		classifyService.save(classify);

        return R.ok();
    }

    /**
     * 保存
     */
    @RequestMapping("/save/classify")
    //@RequiresPermissions("sulingpxqg:classify:save")
    public R saveClassify( ClassifyEntity classify){
        classifyService.save(classify);

        //查询获取用户的所有集合
        List<ClassifyEntity> classifys = classifyService.list(new QueryWrapper<ClassifyEntity>().eq("cl_member_username", classify.getClMemberUsername()).orderByAsc("cl_sort"));
        return R.ok().put("classifys",classifys);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("sulingpxqg:classify:update")
    public R update(@RequestBody ClassifyEntity classify){
		classifyService.updateById(classify);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("sulingpxqg:classify:delete")
    public R delete(@RequestBody Long[] clIds){
		classifyService.removeByIds(Arrays.asList(clIds));

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/deletebyid")
    //@RequiresPermissions("sulingpxqg:classify:delete")
    public R deleteByid(@RequestParam("clId") Long clId){
        classifyService.removeById(clId);

        return R.ok();
    }

}
